<?php
namespace Client\Table;

use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;

use Zend\Paginator\Paginator;
use Zend\Db\Sql\Where;
use Zend\Db\ResultSet\ResultSet;

class OrderTable extends CommonTable
{
    protected $table = 'hy_order';
    protected $id = 'order_id';

    /**
     * 根据单位类目ID取商品
     * @param unknown $cate_id
     * @return unknown
     */
    public function getOrderList($query = array())
    {
        $select = new Select(array('o'=>$this->getTable()));
        $select->columns( array(
            "*"
        ));
    
        $select->join(
            array('org' => 'hy_organization'),
            'org.org_id = o.org_id',
            array('org_id','org_name','org_logo') ,
            $select::JOIN_LEFT
            );
        
        $select->join(
            array('oc' => 'hy_order_score'),
            'o.order_id = oc.order_id',
            array('has_score') ,
            $select::JOIN_LEFT
            );
        
        $select->join(
            array('ro' => 'hy_return_order'),
            'o.order_id = ro.order_id',
            array('return_status'=>'status') ,
            $select::JOIN_LEFT
            );
        
        $select->where(array('o.user_id'=>$query['user_id']));
    
        $select->order(array('o.order_id desc'));
    
        $rowset = $this->selectWith($select);
        $list = $rowset->toArray();
    
        return $list;
    }
    
    public function getByOrderNo($order_no)
    {
        $rowset = $this->select(array('order_no' => $order_no));
        $row = $rowset->current();
        return $row;
    }
}